POW.nicename = "Regeneration"
POW.type = "Alwayse"
POW.help = "You heal fast, and respawn where you die 3 times in a row."
POW.delay = 0.1
POW.lifes = 3
POW.deathpos = {}

function POW:KeyPress( key )
end

function POW:KeyRelease( key )
end

function POW:Initialize()
	Msg("Auto Regeneration has been loaded!\n")
end

function POW:Disabled()
	self.owner:PrintMessage(3, self.owner:Name().. " no longer has " ..self.nicename.. ".")
	for k, v in pairs(player.GetAll()) do
		if ( v.currentpower.power and v.currentpower.power.nicename == "Regeneration V1" ) then
			return
		end
	end
	hook.Remove( "PlayerDeath", "Regeneration V1.PlayerDeath" )
	hook.Remove( "PlayerSpawn", "Regeneration V1.PlayerSpawn" )
end

function POW:Enabled()
	hook.Add( "PlayerDeath", "Regeneration V1.PlayerDeath", self.PlayerDeath )
	hook.Add( "PlayerSpawn", "Regeneration V1.PlayerSpawn", self.PlayerSpawn )
	self.owner:PrintMessage(3, self.owner:Name().. " now has " ..self.nicename.. ".")
end

function POW:Think()
	local health = self.owner:Health()
	if( health < self.owner:GetMaxHealth() and self.nextfire < CurTime()) then
		self.owner:SetHealth( health+1 )
		self.nextfire = CurTime() + self.delay
	end
end


function POW.PlayerDeath( victim, weapon, killer )
	if( victim.currentpower.power and victim.currentpower.power.nicename == "Regeneration V1" ) then
		victim.currentpower.power.deathpos = victim:GetPos()
	end
end

function POW.PlayerSpawn( player )
	if( player.currentpower.power and player.currentpower.power.nicename == "Regeneration V1" ) then
		if( player.currentpower.power.lifes > 0 ) then
			player:SetPos( Vector( player.currentpower.power.deathpos.x, player.currentpower.power.deathpos.y, player.currentpower.power.deathpos.z ) )
			player.currentpower.power.lifes = player.currentpower.power.lifes - 1
		else
			player.currentpower.power.lifes = 3
		end
	end
end
